//
//  ViewController.m
//  10606
//
//  Created by student on 16/3/2.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIView *view1=[[UIView alloc]init];
    view1.backgroundColor=[UIColor blueColor];
    view1.translatesAutoresizingMaskIntoConstraints=NO;
    [self.view addSubview:view1];
    UIView *view2=[[UIView alloc]init];
    view2.backgroundColor=[UIColor redColor];
    view2.translatesAutoresizingMaskIntoConstraints=NO;
    [self.view addSubview:view2];
    NSNumber *margin=@20;
    NSString *vfr1=@"H:|-margin-[view1]-margin-[view2(==view1)]-margin-|";
    NSDictionary *viewdict1=NSDictionaryOfVariableBindings(view1,view2);
    NSDictionary *metrics1=NSDictionaryOfVariableBindings(margin);
    NSArray *constraints=[NSLayoutConstraint constraintsWithVisualFormat:vfr1
                          options:kNilOptions
                          metrics:metrics1
                          views:viewdict1];
    [self.view addConstraints:constraints];
    NSNumber *height=@40;
    NSString *vfr2=@"V:|-[view1(height)]-margin-|";
    NSDictionary *viewdict2=NSDictionaryOfVariableBindings(view1);
    NSDictionary *metrics2=NSDictionaryOfVariableBindings(margin,height);
    NSArray *constraints2=[NSLayoutConstraint constraintsWithVisualFormat:vfr2
                                                                 options:kNilOptions
                                                                 metrics:metrics2
                                                                   views:viewdict2];
    [self.view addConstraints:constraints2];

    NSString *vfr3=@"V:|-[view2(height)]-margin-|";
    NSDictionary *viewdict3=NSDictionaryOfVariableBindings(view2);
    NSDictionary *metrics3=NSDictionaryOfVariableBindings(margin,height);
    NSArray *constraints3=[NSLayoutConstraint constraintsWithVisualFormat:vfr3
                                                                  options:kNilOptions
                                                                  metrics:metrics3
                                                                    views:viewdict3];
    [self.view addConstraints:constraints3];
    
    
    UIView *blueview=[[UIView alloc]init];
    blueview.backgroundColor=[UIColor blueColor];
    blueview.translatesAutoresizingMaskIntoConstraints=NO;
    UIView *redview=[[UIView alloc]init];
    redview.backgroundColor=[UIColor redColor];
    redview.translatesAutoresizingMaskIntoConstraints=NO;
    [self.view addSubview:blueview];
    [self.view addSubview:redview];
    
    
    NSNumber *margin2=@20;
    CGFloat w=self.view.bounds.size.width;
    float ww=(w-40)/2+20;
    NSNumber *width=[[NSNumber alloc]initWithFloat:ww];
    NSNumber *high=@40;
    NSString *vfr4=@"H:|-margin2-[blueview]-margin2-|";
    NSDictionary *viewdict4=NSDictionaryOfVariableBindings(blueview);
    NSDictionary *metrics4=NSDictionaryOfVariableBindings(margin2);
    NSArray *constraints4=[NSLayoutConstraint constraintsWithVisualFormat:vfr4
                                                                  options:kNilOptions
                                                                  metrics:metrics4
                                                                    views:viewdict4];
    [self.view addConstraints:constraints4];

    NSString *vfr5=@"H:|-width-[redview]-margin2-|";
    NSDictionary *viewdict5=NSDictionaryOfVariableBindings(redview);
    NSDictionary *metrics5=NSDictionaryOfVariableBindings(width,margin2);
    NSArray *constraints5=[NSLayoutConstraint constraintsWithVisualFormat:vfr5
                                                                  options:kNilOptions
                                                                  metrics:metrics5
                                                                    views:viewdict5];
    [self.view addConstraints:constraints5];
    
    
    NSString *vfr6=@"V:|-margin2-[blueview(high)]-margin2-[redview(==blueview)]";
    NSDictionary *viewdict6=NSDictionaryOfVariableBindings(blueview,redview);
    NSDictionary *metrics6=NSDictionaryOfVariableBindings(margin2,high);
    NSArray *constraints6=[NSLayoutConstraint constraintsWithVisualFormat:vfr6
                                                                  options:kNilOptions
                                                                  metrics:metrics6
                                                                    views:viewdict6];
    [self.view addConstraints:constraints6];
    


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
